project(engine)

# Function to find the latest Vulkan SDK version in a given directory - needed for good old Windows
function(find_latest_vulkan_sdk base_path output_var)
    file(GLOB SDK_VERSIONS "${base_path}/*")
    list(SORT SDK_VERSIONS ORDER DESCENDING)
    foreach(version IN LISTS SDK_VERSIONS)
        if(IS_DIRECTORY "${version}")
            set(${output_var} "${version}" PARENT_SCOPE)
            return()
        endif()
    endforeach()
    message(FATAL_ERROR "No Vulkan SDK version found in ${base_path}")
endfunction()

find_package(Vulkan REQUIRED)

# Source files
file(GLOB SRC_FILES 
    ${ENGINE_DIR}/*.hpp
    ${ENGINE_DIR}/*.cpp
)

add_library(engine SHARED ${SRC_FILES})


# Library linking is OS dependent
if(UNIX)
	message(STATUS "Adding Linux dependencies")
	# On linux let's override the output directory
	set_target_properties(engine PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/dist")

elseif(WIN32)
	message(STATUS "Adding Windows dependencies")

	# Set the base path for Vulkan SDK
	set(VULKAN_SDK_BASE_PATH "D:/VulkanSDK")

	# Find the latest Vulkan SDK version
	find_latest_vulkan_sdk(${VULKAN_SDK_BASE_PATH} VULKAN_SDK_PATH)

	message(STATUS "Found Vulkan SDK at: ${VULKAN_SDK_PATH}")
	
    # Add Vulkan include directory
    target_include_directories(engine PUBLIC "${VULKAN_SDK_PATH}/Include")
	target_link_libraries(engine PRIVATE "${VULKAN_SDK_PATH}/Lib/vulkan-1.lib")
endif()